//
//  JiaoYiPageViewController.m
//  DBAChain
//
//  Created by Evan on 2018/9/6.
//  Copyright © 2018 Evan. All rights reserved.
//

#import "JiaoYiPageViewController.h"
#import "CommonData.h"
#import <Masonry.h>
#import "JiaoYiZheTableViewCell.h"
#import "JiaoYiMMTableViewCell.h"
#import "JiaoYiSearchTabTableViewCell.h"
#import "JiaoYiMMListTableViewCell.h"
#import "JiaoYiPassWordView.h"
#import "JiaoYiSuccessViewController.h"
#import "JiaoYiDetailViewController.h"
#import "ZheXianTableViewCell.h"
#import "HomePassWordView.h"
#import "DWTabView.h"
#import "taskJiaoYiService.h"
#import "BBNewTableViewCell.h"
#import <WebKit/WebKit.h>
#import "viewPayValidate.h"
#import "taskUserManagerService.h"
#import "MeAuthenticationViewController.h"
#import "MeModifyViewController.h"
#import "MeSecurityViewController.h"
#import "AssetsOrderListViewController.h"

@interface JiaoYiPageViewController ()<UITableViewDelegate,UITableViewDataSource,WKUIDelegate,UIWebViewDelegate>

@property (nonatomic,strong)    UITableView *tableView;
@property (nonatomic,strong)    NSArray<dataTransSaleBuyOrder*> *    orderList;
@property (nonatomic,strong)    NSArray<dataTradPriceInfo*> *    tradeList;
@property (nonatomic,strong)    HomePassWordView*   viewPassword;
@property (nonatomic,strong)    JiaoYiPassWordView *viewConfrimInfo;
@property (nonatomic,strong)    viewPayValidate  *viewPayValid;
@property (nonatomic,strong)    dataUserValidateInfo    *modelUserValidate;

@property (nonatomic,assign)    BOOL isGTE; /**< 是否是GTE   */
@property (nonatomic,strong)    DWTabView        *tabView;
@property (nonatomic,strong)    UIWebView *webView;
@property (nonatomic,strong)    NSMutableArray *bbArray;
@property (nonatomic,strong)    NSString *btc;
@property (nonatomic,strong)    NSString *eth;
@property (nonatomic,strong)    NSString *xrp;

@property (nonatomic,assign)    NSInteger   segmIsIndex;
//买卖表单index
@property (nonatomic,assign)    NSInteger   segmIsIndexMM;

///用户支付密码
@property (nonatomic,strong)    NSString *strPayPwd;
@end

@implementation JiaoYiPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = COLOR_Background_black;
    [self initUI];
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[UserCenter shareCenter]refreshProfiles:^(dataGetUserInfo *profile) {
         [self loadPayValidate];
    }];
    
    self.hidesBottomBarWhenPushed = NO;
    if (self.tabBarController.tabBar.hidden == YES) {
        self.tabBarController.tabBar.hidden = NO;
    }
    if (self.navigationController.navigationBar.hidden == NO) {
        self.navigationController.navigationBar.hidden = YES;
    }
    
    [self loadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidDisappear:(BOOL)animated{
    self.viewConfrimInfo.hidden = YES;
    self.viewPassword.hidden = YES;
    self.viewPassword.txtPwd.text = @"";
    self.strPayPwd = @"";
}

-(void)initUI{
    
    self.isGTE = YES;
    _tabView = [[DWTabView alloc]initWithFrame:CGRectMake(0, 30, KScreenWidth, 40)];
    [self.view addSubview:_tabView];
    self.tabView.selectColor = [UIColor whiteColor];
    self.tabView.normalColor = [UIColor whiteColor];
    self.tabView.items = @[@"GTE交易",@"币币交易"];
    self.tabView.backgroundColor = [UIColor clearColor];
    self.tabView.indicatorPosition = BMTabViewIndicatorPoistionBottom;
     __weak typeof(self) weakSelf = self;
    self.tabView.selection = ^(NSUInteger index, NSUInteger oldIndex) {
        weakSelf.isGTE = index == 0 ? YES : NO;
        [weakSelf.tableView reloadData];
    };
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.mas_equalTo(self.view);
        make.top.offset(70);
        make.bottom.mas_equalTo(self.view).offset(-48);
    }];
}



///获取登录用户的账户验证信息资料
-(void)loadPayValidate{
    [taskUserManagerService getUserValidateInfo:nil success:^(dataUserValidateInfo *response, BOOL success) {
        [DKProgressHUD dismiss];
        if (success) {
            
            self.modelUserValidate =  [dataUserValidateInfo mj_objectWithKeyValues:response];
            [self isValidateSuccess];
        }else{
            [DKProgressHUD showErrorWithStatus:response.statusDesc];
        }
    } failture:^(NSError *error, NSString *strDescription) {
        [DKProgressHUD dismiss];
        [DKProgressHUD showErrorWithStatus:strDescription];
    }];
}

-(BOOL) isValidateSuccess{
    self.viewPayValid.hidden = YES;
    if (!self.modelUserValidate.infoVerify || !self.modelUserValidate.payPasswordVerify) {
        self.viewPayValid.hidden = NO;
        
        //隐藏安全验证信息
        self.viewPayValid.labelNo3.hidden = YES;
        self.viewPayValid.imgNo3.hidden = YES;
        
        UIColor *colorF = LCFromRGB(240, 92, 164);
        UIColor *colorF_no = LCFromRGB(102, 102, 102);
        UIImage *imgleftCheck = [UIImage imageNamed:@"leftCheck"];
        UIImage *imgleftCheck_no = [UIImage imageNamed:@"leftCheck_no"];
        
        self.viewPayValid.labelNo1.textColor = colorF_no;
        self.viewPayValid.imgNo1.image = imgleftCheck_no;
        self.viewPayValid.labelNo2.textColor = colorF_no;
        self.viewPayValid.imgNo2.image = imgleftCheck_no;
        self.viewPayValid.labelNo3.textColor = colorF_no;
        self.viewPayValid.imgNo3.image = imgleftCheck_no;
        
        if (self.modelUserValidate.payPasswordVerify == 1) {
            self.viewPayValid.labelNo1.textColor = colorF;
            self.viewPayValid.imgNo1.image = imgleftCheck;
            
        }
        if (self.modelUserValidate.infoVerify == 1) {
            self.viewPayValid.labelNo2.textColor = colorF;
            self.viewPayValid.imgNo2.image = imgleftCheck;
        }
//        if (self.modelUserValidate.safeVerify == 1) {
//            self.viewPayValid.labelNo3.textColor = colorF;
//            self.viewPayValid.imgNo3.image = imgleftCheck;
//        }
        
        NSString *str = @"设置支付密码";
        if (!(self.modelUserValidate.payPasswordVerify == 1)) {
            str = @"设置支付密码";
        }else if(!(self.modelUserValidate.infoVerify == 1)){
            str = @"实名认证";
        }
//        else if(!(self.modelUserValidate.safeVerify == 1)){
//            str = @"安全认证";
//        }
        [self.viewPayValid.btnSubmit setTitle:str forState:UIControlStateNormal];
        
        return NO;
    }
    return YES;
}

-(viewPayValidate*)viewPayValid{
    if (!_viewPayValid ){
        _viewPayValid = [[[NSBundle mainBundle] loadNibNamed:@"viewPayValidate" owner:nil options:nil] objectAtIndex:0];
        [_viewPayValid initUI];
        [self.view addSubview:_viewPayValid];
        _viewPayValid.hidden = YES;
        [_viewPayValid mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.mas_equalTo(self.view);
            make.top.offset(60);
            make.bottom.mas_equalTo(self.view).offset(0);
        }];
        [_viewPayValid.btnSubmit addTarget:self action:@selector(btnSubmitClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _viewPayValid;
}

///用户验证点击完成
-(void)btnSubmitClick:(UIButton*)sender{
    if (!self.modelUserValidate.payPasswordVerify) {
        //跳转到设置支付密码页面
        [self.navigationController pushViewController:[[MeModifyViewController alloc]initWithType:1] animated:YES];
    }else if(!self.modelUserValidate.infoVerify){
        //跳转到实名认证页面
        [self.navigationController pushViewController:[MeAuthenticationViewController new] animated:YES];
    }
//    else if(!self.modelUserValidate.safeVerify){
//        //跳转到安全认证页面
//        [self.navigationController pushViewController:[MeSecurityViewController new] animated:YES];
//    }
}


-(JiaoYiPassWordView*)viewConfrimInfo{
    if (!_viewConfrimInfo) {
        _viewConfrimInfo = [[[NSBundle mainBundle] loadNibNamed:@"JiaoYiPassWordView" owner:nil options:nil] objectAtIndex:0];
        [self.view addSubview:_viewConfrimInfo];
        _viewConfrimInfo.hidden = YES;
        [_viewConfrimInfo initUI];
        [_viewConfrimInfo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.mas_equalTo(self.view);
            make.top.offset(60);
            make.bottom.mas_equalTo(self.view).offset(0);
        }];
    }
    return _viewConfrimInfo;
}


-(HomePassWordView*)viewPassword{
    if (!_viewPassword ){
        _viewPassword = [[[NSBundle mainBundle] loadNibNamed:@"HomePassWordView" owner:nil options:nil] objectAtIndex:0];
        [_viewPassword initUI];
        [self.view addSubview:_viewPassword];
        _viewPassword.hidden = YES;
        [_viewPassword mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.mas_equalTo(self.view);
            make.top.offset(60);
            make.bottom.mas_equalTo(self.view).offset(0);
        }];
    }
    return _viewPassword;
}

#pragma mark - loaddata

- (void)loadData{
   
    [self loadTradePrice];
    [self loadOrderList];
    self.bbArray = [NSMutableArray new];
    [self loadBB];
}

///加载折线图数据
-(void)loadTradePrice{
    
    [DKProgressHUD showLoading];
    [taskJiaoYiService getTradPrice:nil success:^(dataTradPrice *response, BOOL success) {
        [DKProgressHUD dismiss];
        if (success) {
            self.tradeList = response.data;
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationNone];
        }else{
            [DKProgressHUD showErrorWithStatus:response.description];
        }
        
    } failture:^(NSError *error, NSString *strDescription) {
        [DKProgressHUD dismiss];
        [DKProgressHUD showErrorWithStatus:strDescription];
    }];
}

///加载订单列表
-(void)loadOrderList{
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:@(0) forKey:@"page"];
    [dict setValue:@(50) forKey:@"pageSize"];
    [dict setValue:@(self.segmIsIndex) forKey:@"orderType"];
    
    [taskJiaoYiService getTransSaleBuyList:dict success:^(dataTransSaleBuy *response, BOOL success) {
        [DKProgressHUD dismiss];
        if (success) {
            self.orderList = response.orderList;
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:4] withRowAnimation:UITableViewRowAnimationNone];
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
        }else{
            [DKProgressHUD showErrorWithStatus:response.description];
        }
        
    } failture:^(NSError *error, NSString *strDescription) {
        [DKProgressHUD dismiss];
        [DKProgressHUD showErrorWithStatus:strDescription];
    }];
}

-(void)loadBB{
    self.webView = [UIWebView new];
    self.webView.delegate = self;
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.zb.cn/data/v1/ticker?market=btc_qc"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5.0]];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    // Disable user selection
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
    // Disable callout
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];

    NSString *body =  [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerText"];
    
    [self.bbArray addObject:[[[Check dictionaryWithJsonString:body] valueForKey:@"ticker"] valueForKey:@"last"]];
    if (self.bbArray.count == 1) {
        self.btc = self.bbArray[0];
        [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.zb.cn/data/v1/ticker?market=eth_qc"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5.0]];
    }else if (self.bbArray.count == 2){
        self.eth = self.bbArray[1];
        [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.zb.cn/data/v1/ticker?market=xrp_qc"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5.0]];
    }else{
        self.xrp = self.bbArray[2];
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
    }
}


#pragma mark - tableivew


-(UITableView *)tableView{
    if (!_tableView) {
        self.automaticallyAdjustsScrollViewInsets = NO;
        _tableView = [[UITableView alloc]init];
        [self.view addSubview:_tableView];
        
        _tableView.dataSource = self;
        _tableView.delegate = self;
        //定义显示默认cell的横线
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor  = [UIColor clearColor];
    }
    return _tableView;
}

#pragma mark - UITableViewDelegate

//定义每一个section有多少row
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 4) {
        return [self.orderList count];
    }
    return 1;
}

//定义有多少section
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}

//定义CellRow的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
        {
            return 60;//439;
        }
            break;
        case 1:///统计图
        {
            return self.isGTE ? 300 : 190;
        }
            break;
        case 2:
        {
            return 420;
        }
            break;
        case 3:
        {
            return 63;
        }
            break;
            
        default:
            break;
    }
    return 100;
}

//定义section的Footer的view视图
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [UIView new];
    view.backgroundColor = COLOR_Background;
    return view;
}

//定义section的Footer的高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}


//定义section的header的view视图
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [UIView new];
    view.backgroundColor = COLOR_Background;
    return view;
}

//定义section的header的高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section >3) {
        return 1;
    }
    return 0;
}

//主体cell的内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        NSString *strIndexCell = [NSString stringWithFormat:@"JiaoYiZheTableViewCell_%ld_%ld",(long)indexPath.section,(long)indexPath.row];
        JiaoYiZheTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strIndexCell];
        if (!cell) {
            [self.tableView registerClass:[JiaoYiZheTableViewCell class] forCellReuseIdentifier:strIndexCell];
            cell = [tableView dequeueReusableCellWithIdentifier:strIndexCell forIndexPath:indexPath];
            [cell initUI];
        }
        cell.backgroundColor = COLOR_Background_black;
        cell.labelUpDes.hidden = !self.isGTE;
        cell.labelUp.hidden = !self.isGTE;
        if (self.isGTE) {
            NSInteger indexC  = self.tradeList.count -1;
             dataTradPriceInfo *mm = [dataTradPriceInfo mj_objectWithKeyValues:[self.tradeList objectAtIndex:indexC]];

            cell.labelCNY.text = [NSString stringWithFormat:@"当前价格：%.2f CNY",mm.price];

            dataTradPriceInfo *mm2 = [dataTradPriceInfo mj_objectWithKeyValues:[self.tradeList objectAtIndex:indexC-1]];
            CGFloat x1 = [@(mm.price - mm2.price) floatValue];
            CGFloat xx = x1/[@(mm.price) floatValue];
            NSString *strUp = @"";
            xx = xx*100;
            if (xx >=0) {
                strUp =  [NSString stringWithFormat:@"+%.2f%%",xx];
            }else{
                strUp =  [NSString stringWithFormat:@"-%.2f%%",xx];
            }
            cell.labelUpDes.text =  strUp ;
        }else{
            cell.labelCNY.text = @"简易行情";
        }
        return cell;
    }else if(indexPath.section == 1){
        if (self.isGTE) {
            ZheXianTableViewCell *cell = [ZheXianTableViewCell cellWithTableView:tableView IndexPath:indexPath];
            [cell initData:self.tradeList];
            cell.aaChartView.backgroundColor = COLOR_Background_black;
            return cell;
        }else{
            BBNewTableViewCell *cell = [BBNewTableViewCell cellWithTableView:tableView];
            cell.lab.text = [NSString stringWithFormat:@"1BTC = %@ CNY",self.btc];
            cell.lab1.text = [NSString stringWithFormat:@"1ETC = %@ CNY",self.eth];
            cell.lab2.text = [NSString stringWithFormat:@"1XRP = %@ CNY",self.xrp];
            cell.lab3.text = [NSString stringWithFormat:@"1GTE =%.7f BTC",(1/[self.btc floatValue])];
            cell.lab4.text = [NSString stringWithFormat:@"1GTE =%.7f ETC",(1/[self.eth floatValue])];
            cell.lab5.text = [NSString stringWithFormat:@"1GTE =%.7f XRP",(1/[self.xrp floatValue])];
            return cell;
        }
    }else if(indexPath.section == 2){
        
        NSString *strIndexCell = [NSString stringWithFormat:@"JiaoYiMMTableViewCell_%ld_%ld",(long)indexPath.section,(long)indexPath.row];
        JiaoYiMMTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strIndexCell];
        if (!cell) {
            [self.tableView registerClass:[JiaoYiMMTableViewCell class] forCellReuseIdentifier:strIndexCell];
            cell = [tableView dequeueReusableCellWithIdentifier:strIndexCell forIndexPath:indexPath];
            [cell initUI];
        }
        NSInteger indexC  = self.tradeList.count -1;
        dataTradPriceInfo *mm = [dataTradPriceInfo mj_objectWithKeyValues:[self.tradeList objectAtIndex:indexC]];
        
        cell.viewJY.txtMRPrice.text = [NSString stringWithFormat:@"%.2f",mm.price];
        
        [cell.segmCheck addTarget:self action:@selector(segmentValueChangedMM:)forControlEvents:UIControlEventValueChanged];
        [cell.viewJY.btnSubmit addTarget:self action:@selector(btnSubmitMR:) forControlEvents:UIControlEventTouchUpInside];
        cell.viewJY.labelGET.text = [NSString stringWithFormat:@"%.2f GTE",[UserCenter shareCenter].user.gteCoin];
        return cell;
    }else if(indexPath.section == 3){
        
        NSString *strIndexCell = [NSString stringWithFormat:@"JiaoYiSearchTabTableViewCell_%ld_%ld",(long)indexPath.section,(long)indexPath.row];
        JiaoYiSearchTabTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strIndexCell];
        if (!cell) {
            [self.tableView registerClass:[JiaoYiSearchTabTableViewCell class] forCellReuseIdentifier:strIndexCell];
            cell = [tableView dequeueReusableCellWithIdentifier:strIndexCell forIndexPath:indexPath];
            [cell initUI];
        }
        [cell.segmCheck addTarget:self action:@selector(segmentValueChanged:)forControlEvents:UIControlEventValueChanged];
        return cell;
    }else if(indexPath.section == 4){
        
        NSString *strIndexCell = [NSString stringWithFormat:@"JiaoYiMMListTableViewCell_%ld_%ld",indexPath.section,indexPath.row];
        JiaoYiMMListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strIndexCell];
        if (!cell) {
            [self.tableView registerNib:[UINib nibWithNibName:@"JiaoYiMMListTableViewCell" bundle:nil] forCellReuseIdentifier:strIndexCell];
            cell = [tableView dequeueReusableCellWithIdentifier:strIndexCell forIndexPath:indexPath];
        }
        
        dataTransSaleBuyOrder* m = [self.orderList objectAtIndex:indexPath.row];
        dataTransSaleBuyOrder *mm = [dataTransSaleBuyOrder mj_objectWithKeyValues:m];
        
        cell.labelLimit.text = [NSString stringWithFormat:@"限额：%@CNY",mm.limitAmount];
        cell.labelTitle.text = mm.userName;
        cell.labelCJRate.text = [NSString stringWithFormat:@"成交率 %@",mm.successRate];
        cell.labelCJCount.text = [NSString stringWithFormat:@"成交 %@",mm.sucessCout];
        cell.labelNumber.text = [NSString stringWithFormat:@"数量: %ld GTE",(long)mm.number];
        cell.labelOrderAmount.text = [NSString stringWithFormat:@"%@ CNY",mm.orderAmount];
        cell.labelPrice.text = [NSString stringWithFormat:@"单价: %@CNY",mm.price];
        return cell;
    }
    return [UITableViewCell new];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    if(indexPath.section >= 4){
        JiaoYiDetailViewController *vc = [[JiaoYiDetailViewController alloc]initWithNibName:@"JiaoYiDetailViewController" bundle:nil];
        dataTransSaleBuyOrder* m = [self.orderList objectAtIndex:indexPath.row];
        dataTransSaleBuyOrder *mm = [dataTransSaleBuyOrder mj_objectWithKeyValues:m];
        vc.modelDetail = mm;
        vc.isGouMai = self.segmIsIndex == 0;
        [self.navigationController pushViewController:vc animated:YES];
    }
}


#pragma mark - segmValueChanage


-(void)segmentValueChangedMM:(UISegmentedControl*)sender{
    if (sender.selectedSegmentIndex == 2) {
        ///订单详情
        /////需要跳转到交易中的订单列表
        [self.navigationController pushViewController:[AssetsOrderListViewController new] animated:YES];
        return ;
    }
    self.segmIsIndexMM = sender.selectedSegmentIndex;
    JiaoYiMMTableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]];
    if (self.segmIsIndexMM == 0) {
        cell.viewJY.txtMRPrice.placeholder = @"请输入买入价格";
        cell.viewJY.txtMRNumber.placeholder = @"请输入购买数量";
    }else{
        cell.viewJY.txtMRPrice.placeholder = @"请输入卖出价格";
        cell.viewJY.txtMRNumber.placeholder = @"请输入卖出数量";
    }
}

///求购售出列表类型
-(void)segmentValueChanged:(UISegmentedControl*)sender{
    self.segmIsIndex = sender.selectedSegmentIndex;
    [self loadOrderList];
}



#pragma mark - 购买

///购买买入提交按钮
-(void)btnSubmitMR:(UIButton*)sender{
    NSLog(@"点击了购买GTE按钮");
    
    JiaoYiMMTableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]];
    
    if ([cell.viewJY.txtMRNumber.text integerValue] < 100 || [cell.viewJY.txtMRNumber.text integerValue] > 2000 ) {
        [DKProgressHUD showErrorWithStatus:@"请输入100-2000个范围的GTE"];
        return;
    }
    if (cell.viewJY.txtMRPrice.text.length ==0) {
        [DKProgressHUD showErrorWithStatus:@"请输入正确的金额"];
        return;
    }
    if (cell.viewJY.txtMRXE.text.length ==0) {
        [DKProgressHUD showErrorWithStatus:@"请输入正确的限额"];
        return;
    }
    
    
    ///进入输入密码的模块
    self.viewPassword.hidden = NO;
    __block JiaoYiPageViewController *  blockSelf = self;
    self.viewPassword.blockSubmit = ^(NSString *pwd) {
        blockSelf.strPayPwd = pwd;
        JiaoYiMMTableViewCell *cell = [blockSelf.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]];
        
        blockSelf.viewPassword.hidden = YES;
        blockSelf.viewPassword.txtPwd.text = @"";
        
        blockSelf.viewConfrimInfo.hidden = NO;
        
        blockSelf.viewConfrimInfo.labelNumber.text = [NSString stringWithFormat:@"%@ GTE",cell.viewJY.txtMRNumber.text];
        blockSelf.viewConfrimInfo.labelMJ.text = [NSString stringWithFormat:@"%@ CNY",cell.viewJY.txtMRPrice.text];
        blockSelf.viewConfrimInfo.labelZJ.text = cell.viewJY.labelHeJi.text;
        blockSelf.viewConfrimInfo.labelXE.text =  [NSString stringWithFormat:@"%@ CNY",cell.viewJY.txtMRXE.text];
        
        [blockSelf.viewConfrimInfo.btnConfrim addTarget:blockSelf action:@selector(btnInfoConfrim:) forControlEvents:UIControlEventTouchUpInside];
    };
}

///确认信息后点击提示
-(void)btnInfoConfrim:(UIButton*)sender{
    NSLog(@"确认过信息");
    self.viewConfrimInfo.hidden = YES;
    
    JiaoYiMMTableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]];
    
    NSInteger sNumber = [cell.viewJY.txtMRNumber.text integerValue];
    NSString*     sPrice = cell.viewJY.txtMRPrice.text;
    
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:[UserCenter shareCenter].user.userNo forKey:@"userNo"];
    [dict setValue:sPrice forKey:@"price"];
    [dict setValue:@(sNumber*[sPrice floatValue]) forKey:@"amount"];
    [dict setValue:@(sNumber) forKey:@"number"];
    [dict setValue:@(self.segmIsIndexMM) forKey:@"orderType"];
    [dict setValue:cell.viewJY.txtMRXE.text forKey:@"limitAmount"];
    [dict setValue:self.strPayPwd forKey:@"payPassword"];
    
    [DKProgressHUD showLoading];
    [taskJiaoYiService getTransSaleBuyGTE:dict success:^(dataTransSaleBuyGTE *response, BOOL success) {
        [DKProgressHUD dismiss];
        if (success) {
            JiaoYiSuccessViewController *vc = [JiaoYiSuccessViewController new];
            vc.isMaiRu = self.segmIsIndexMM == 0 ? YES : NO;
            [self.navigationController pushViewController:vc animated:YES];
            [self.tableView reloadData];
            return;
        }
        [DKProgressHUD showErrorWithStatus:response.statusDesc];
    } failture:^(NSError *error, NSString *strDescription) {
        [DKProgressHUD dismiss];
        [DKProgressHUD showErrorWithStatus:strDescription];
    }];
}


#pragma mark - touch view

-  (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}


@end
